import Api from '../../api'
export default{

    state:{
        commentList:[],
        commentListByPage:{}
    },
    actions:{
        // 获取评论信息
        async getCommentData({commit}){
                const {data:res} = await Api.getCommentList();
                if(res.status == 200) 
                 commit('GETCOMMENTDATA',res.data);
                return new Promise((resovle,reject)=>{
                    if(res.status == 200) resovle(true);
                    else reject(false);
                })
        },
        // 获取评论信息(分页)
        async getCommentListByPage({commit},pagination){
            const {data:res} = await Api.getCommentListByPage(pagination);
            if(res.status == 200) 
             commit('GETCOMMENTDATABYPAGE',res.data);
            return new Promise((resovle,reject)=>{
                if(res.status == 200) resovle(true);
                else reject(false);
            })
        },
        async deleteCommentData({commit},comId){
                console.log(commit);
                const {data:res} = await Api.removeCommentList(comId)
                return new Promise((resovle,reject)=>{
                    if(res.status == 200) resovle(true);
                    else reject(false);
                })
        },
        // 关键字查找
        async searchComment({commit},query){
            const {data:res} = await Api.searchCommentList(query);
             if(res.status == 200) {
                 commit("GETCOMMENTDATA",res.data)
             }
        },
        // 添加评论
        async addComment({commit},pload){
            console.log(commit);
            const {data:res} = await Api.addCommentList(pload);
             return new Promise((resovle,reject)=>{
                if(res.status == 201) resovle(true);
                else reject(false);
            })
        },
    },
    mutations:{
        // 获取球馆信息
        GETCOMMENTDATA(state,commentList){
            state.commentList = commentList;
        },
        GETCOMMENTDATABYPAGE(state,commentListByPage){
            state.commentListByPage = commentListByPage;
        }
        
    },
    getters:{
        commentList(state){
            return state.commentList||[];
        },
        commentListByPage(state){
            return state.commentListByPage||{};
        }
    }
}